package com.takepoints.mobile.dialog;

import com.takepoints.mobile.R;
import com.takepoints.android.util.DownloadImageTask;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class ImgPreviewDlg extends Dialog implements DialogInterface {
	
	private String imgUrl;
	private String imgSdPath;
	
	public ImgPreviewDlg(Context context) {
		super(context);
	}
	
	@Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.imgdialog);
        //setTitle("title");
        setCancelable(true);
        setCanceledOnTouchOutside(true);
        
        ImageView imgPreview = (ImageView)findViewById(R.id.imgPreview);
        if(getImgSdPath() != null){
        	Bitmap bitmap = BitmapFactory.decodeFile(getImgSdPath());
        	imgPreview.setImageBitmap(bitmap);
        } else{
	        imgPreview.setTag(getImgUrl());
	        new DownloadImageTask().execute(imgPreview);
        }
        
        final Button btnClose = (Button)this.findViewById(R.id.btnClose);
        btnClose.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
            	dismiss();
            }
        });
	}

	public String getImgUrl() {
		return imgUrl;
	}
	public void setImgUrl(String imgUrl) {
		this.imgUrl = imgUrl;
	}

	public String getImgSdPath() {
		return imgSdPath;
	}
	public void setImgSdPath(String imgSdPath) {
		this.imgSdPath = imgSdPath;
	}
	
}
